<html>
<!--
    This work is licensed under Creative Commons GNU LGPL License.

    License: http://creativecommons.org/licenses/LGPL/2.1/
    Version: 0.5
    Author:  Michael Shook/2008
    Web:     http://del.icio.us/mshook
-->
<head>
<title>d4m | del.icio.us for mobile</title>
<style type="text/css">
body {
  font-family: sans-serif;
  font-size: 16px;
  margin: 50px;
}
</style>
<script type="text/javascript" src="jsont.js"></script>
<script>
DHJ = {
    exampleDelPath: "/mshook/foo",
    prefix: "http://feeds.delicious.com/v2/json",
    suffix: "?callback=DHJ.process&count=100",
    template: {

        "self[*]": " <div class='delPost'>"+
                   "<h3><a href='http://del.icio.us/url/?url={$.u}'>&raquo</a> \n"+
                   "  <a class='delLink' href='{$.u}'>{$.d}</a></h3>"+
                   "  {$.n}<span class='delTagSep'>/</span>\n"+
                   "  {$.t}\n"+
                   " </div>\n",
        "self[*].t[*]": "<a class='delTag' href='{urlBase}?/{user}/{$}'>{$}</a> "

    },
    getJavaScript: function(url) {
        document.write("<script src=\"" + url + "\"><\/script>");
    },
    setUser: function(str) {
        document.appform.user.value = str;
    },
    setTags: function(str) {
        document.appform.tags.value = str;
    },
    getContent: function(url) {
        if (url.indexOf("?") == -1) {
            return DHJ.content;
        }
        else {
            return url.split("?")[1] + "?" + url.split("?")[2];
        }
    },
    getUrlBase: function(url) {
        return url.split("?")[0];
    },
    getDelPath: function(url) {
        return url.indexOf("?") ? url.split("?")[1] : "";
    },
    getUser: function(path) {
        return path ? ((path.indexOf("/") == -1) ? "" : path.split("/")[1]) : "";
    },
    getTags: function(path) {
        return path ?
            ((path.indexOf("/") == -1) ?
                "" :
                (path.split("/")[2] ?
                    path.split("/")[2] :
                    "") ) :
            "";
    },
    gotoUserTags: function(urlBase, user, tags) {
        if ((user == "") && (tags == "")) {
            window.location.href = urlBase + "?";
        }
        else if (tags == "") {
            window.location.href = urlBase + "?/" + user;
        }
        else {
            window.location.href = urlBase + "?/" + user + "/" + tags;
        }
    },
    init: function(url) {
        DHJ.urlBase = DHJ.getUrlBase(url);
        DHJ.delPath = DHJ.getDelPath(url);
        DHJ.user = DHJ.getUser(DHJ.delPath);
        DHJ.tags = DHJ.getTags(DHJ.delPath);
        DHJ.template["self[*].t[*]"] = DHJ.template["self[*].t[*]"].supplant(DHJ);
     },
    process: function(json) {
        document.write(jsonT(json, DHJ.template));
        DHJ.setUser(DHJ.user);
        DHJ.setTags(DHJ.tags);
    }

};
// From http://javascript.crockford.com/remedial.html
String.prototype.supplant = function (o) {
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );
};

DHJ.init(window.location.href); 
</script>
</head>
<body>
<a id="top"></a>
<form name="appform">
<label for="user">User:</label>
<input type="text" name="user" size="15">
<!--
<select name="specialusers" width="100" style="width: 100px" onchange="document.appform.user.value = document.appform.specialusers.value">
<option value =""></option>
<option value ="popular">popular</option>
<option value ="tag">tag</option>
</select>
-->
<a href="javascript:DHJ.setUser('popular');">p</a>
<a href="javascript:DHJ.setUser('tag');">t</a>
<a href="javascript:DHJ.setUser('recent');DHJ.setTags('');">r</a>
<a href="javascript:DHJ.setUser('');">b</a>
<label for="tags">tags:</label>
<input type="text" name="tags" size="30">
<a href="javascript:DHJ.setTags('');">b</a>
<input type="button" onclick="DHJ.gotoUserTags(DHJ.urlBase, document.appform.user.value,
    document.appform.tags.value);" value="Go">
<!--
<br />
<label for="url">url:</label>
<input type="text" name="url" size="60">
<input type="button" onclick="DHJ.gotoUrl(document.appform.url.value);" value="Go">
-->
</form>
<script>
document.write(DHJ.delPath);
if (location.href.indexOf("?") == -1) {
    location.href = "http://routeabout.blogspot.com/2008/08/substitute-kludglet-for-delicioushtml.html";
}
else {
    DHJ.getJavaScript("{prefix}{delPath}{suffix}".supplant(DHJ));
    // DHJ.getJavaScript(DHJ.prefix + DHJ.delPath + DHJ.suffix);
}
DHJ.setUser(DHJ.user);
DHJ.setTags(DHJ.tags);
</script>
<a href="#top">top</a>
</body>
</html>

